package com.xdhl.fu.fi.controller;

import com.xdhl.fu.common.core.constant.flightinfo.FlightInfoConstants;
import com.xdhl.fu.common.core.utils.bean.BeanUtils;
import com.xdhl.fu.common.core.web.domain.AjaxResult;
import com.xdhl.fu.fi.repository.MGFlightScheduleRepository;
import com.xdhl.fu.fi.service.IFlightInfoService;
import com.xdhl.fu.flight.info.api.domain.FlightInfo;
import com.xdhl.fu.flight.info.api.domain.vo.FlightInfoVO;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 航线控制器
 *
 * @author 朱力维
 * @time 2022/7/1 14:57
 */
@RestController
@RequestMapping("/flight-line")
public class FlightLineController {

    @Resource
    private MGFlightScheduleRepository flightScheduleRepository;

    @Resource
    private IFlightInfoService flightInfoService;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 查询航线详情
     *
     * @param dataId 航线数据ID
     * @return 航线详情
     */
    @GetMapping("/{dataId}")
    public AjaxResult get(@PathVariable("dataId") String dataId) {
        FlightInfo flightInfo = flightInfoService.getById(dataId);
        BoundHashOperations<String, String, Object> boundHashOperations = stringRedisTemplate.boundHashOps(FlightInfoConstants.AIRPORTS_CACHE_KEY);
        FlightInfoVO flightInfoVO = new FlightInfoVO();
        BeanUtils.copyBeanProp(flightInfoVO, flightInfo);
        flightInfoVO.setStartStationDisplay(boundHashOperations.get(flightInfoVO.getStartStation()).toString());
        flightInfoVO.setEndStationDisplay(boundHashOperations.get(flightInfoVO.getEndStation()).toString());
        return AjaxResult.success(flightInfoVO);
    }
}
